package cn.kgc.crowdfundingadmin.controller;


import cn.kgc.crowdfundingadmin.common.ResultEntity;
import cn.kgc.crowdfundingadmin.pojo.Message;
import cn.kgc.crowdfundingadmin.service.MessageService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class MessageController {

    @Resource
    MessageService messageService;

    //分页查询
    @RequestMapping("/message/search/by/keyword")
    public ResultEntity<PageInfo<Message>> search(
            @RequestParam(value="pageNum", defaultValue="1",required = false) Integer pageNum,
            @RequestParam(value="pageSize", defaultValue="5",required = false) Integer pageSize,
            @RequestParam(value="keyword", defaultValue="",required = false) String keyword
    ) {
        //查询得到pageInfo对象
        PageInfo<Message> pageInfo=messageService.queryForKeywordWithPage(pageNum,pageSize,keyword);
        //封装结果对象返回
        return ResultEntity.successWithoutData(pageInfo);

    }

    @RequestMapping("/message/get/list/by/id/list")
    public ResultEntity<List<Message>> getRoleListByIdList(@RequestBody List<Integer> certIdList) {
        List<Message> list=messageService.getCertListByIdList(certIdList);
        return ResultEntity.successWithoutData(list);

    }

    //更新
    @RequestMapping("/message/update/message")
    public ResultEntity<String> updateRole(Message message) {
        messageService.updateMessage(message);
        return ResultEntity.successWithoutData();
    }

}
